(function () {
    "use strict";

    angular.module('app').service('WctTeletextService', WctTeletextService);

    WctTeletextService.$inject = [
        '$q',
        'A',
        '$toast',
        'Api'
    ];

    function WctTeletextService($q, A, $toast, Api) {

        var service = {
            getWxMenu: getWxMenu,
            sync     : sync
        };

        function getWxMenu() {
            var defer = $q.defer();
            // 处理 result, 新的promise直接返回数据
            A.Ajax.post(Api.wct.menu.list)
                .then(function (result) {
                    result.success ? (defer.resolve(result.data)) : ($toast.warn(result.msg));
                });
            return defer.promise;
        }

        function sync() {
            return A.Ajax.post(Api.wct.menu.sync);
        }

        return service;
    }
})();